import React, { memo, useMemo } from "react";

function Son(props) {
  console.log("子组件渲染");

  // const isAdult = props.age >= 18?"已成年":"未成年";

  // useMemo：防止函数的无效的调用。
  const isAdult = useMemo(() => {
    return props.age >= 18 ? "已成年" : "未成年";
  }, [props.age]);

  return (
    <>
      <h2>子组件</h2>
      <p>姓名:{props.name}</p>
      <p>年龄:{props.age}</p>
      <p>是否成年:{isAdult}</p>
    </>
  );
}

export default memo(Son);
